const BehaviorAll = require("../../../behaviors/behavior_all.js");
const ServiceOrder = require("../../../service/service_order.js");
const ServiceScore = require("../../../service/service_score.js");

Component({
  /**
   * behaviors
   */
  behaviors: [BehaviorAll],
  /**
   * 页面的初始数据
   */
  data: {
    allScore: 0,
    /**
     * 格式
     *  {id:1, number:'a', state:xxx, stateComment:'xxx', totalScore:100.0, amount:3, 
     *    items:[
     *      {id:'{}', name:'xxx', number:'yyy', score:10.0, imgUrl:''}
     *    ],
     *    address: {username:'xx', phone:'123', address: 'asdf'}
     * }
     */
    order: null,
    orderId: null,
    /**
     * 购物车相关
     */
    car_amount: 0,
    triggerRetrieveData: false
  },

  methods:{
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      const _this = this;
      const orderId = options.id;
      _this.setData({ orderId })
      // 加载数据
      ServiceScore.find(function (data) {
        _this.setData({
          allScore: data
        })
      })
      ServiceOrder.findGradeById(orderId, function (data) {
        _this.setData({ order: data })
      });
    },

    /**
    * onShow
    */
    onShow: function (e) {
      const _this = this;
      _this.setData({ triggerRetrieveData: true });
    },

    /**
     * 获取数据
     */
    car_onRetrieve: function (e) {
      const _this = this;
      _this.setData({
        car_amount: e.detail.amount
      })
    },

    onTriggerSubmit: function (e) {
      const _this = this;
      wx.navigateTo({
        url: '../pay/pay?id=' + _this.data.orderId
      })
    }
  }

})